using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    //
    using Model;
    using DAL;
    using System.Collections;
    using BLL.Class;
    using Common;
    using DbFrame.Class;

    public class MemberBL : BaseBLL
    {
        MemberM _MemberM = new MemberM();

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="QuickConditions"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public Sys_PagingEntity GetDataSource(Hashtable query, int page, int rows)
        {
            return new MemberDA().GetDataSource(query, page, rows);
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<SQL> Save(MemberM model)
        {
            if (model.Member_ID.GetGuid().Equals(Guid.Empty))
            {
                model.Member_ID = db.Add(model, li).GetGuid();
                if (model.Member_ID.Equals(Guid.Empty))
                    throw new MessageBox(db.ErrorMessge);
            }
            else
            {
                if (!db.EditById(model, model.Member_ID, li))
                    throw new MessageBox(db.ErrorMessge);
            }
            return li;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public List<SQL> Delete(string ID)
        {
            db.JsonToList<string>(ID).ForEach(item =>
            {
                if (!db.DeleteById<MemberM>(item.GetGuid(), li))
                    throw new MessageBox(db.ErrorMessge);
            });
            return li;
        }

        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public Dictionary<string, object> Find(Guid ID)
        {
            var _MemberM = db.Find<MemberM>(w => w.Member_ID == ID.GetGuid());
            var _Sys_UserM = db.Find<Sys_UserM>(w => w.User_ID == _MemberM.Member_UserID);
            var di = this.EntityToDictionary(new Dictionary<string, object>()
            {
                {"_MemberM",_MemberM},
                {"_Sys_UserM",_Sys_UserM},
                {"status",1}
            });
            if (di.ContainsKey("User_Pwd"))
                di.Remove("User_Pwd");

            //格式化 日期
            di["Member_Birthday"] = di["Member_Birthday"].GetDateTimeString();

            return di;
        }

    }
}
